package org.example.demo02;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;

/**
 * 代理类
 */
public class AccountAdvice implements InvocationHandler, org.springframework.cglib.proxy.InvocationHandler {

    //引入目标对象
    private IAccountService target;

    //重写有参构造
    public AccountAdvice(IAccountService target) {
        this.target = target;
    }


    /**
     * 代理方法, 每次调用目标方法时都会进到这里
     */
    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        before();
        return method.invoke(target,args);
    }

    /**
     * 前置增强
     */
    public void before(){
        System.out.println("对转账人身份进行校验");
    }
}
